<?php
/*
Connect to the local server using Windows Authentication and specify
the AdventureWorks database as the database in use. To connect using
SQL Server Authentication, set values for the "UID" and "PWD"
attributes in the $connectionInfo parameter. For example:
$connectionInfo = array("UID" => $uid, "PWD" => $pwd, "Database"=>"AdventureWorks");
 */
$serverName = "(local)";
$connectionInfo = array("UID" =>"ArisSeco", "PWD" => "1234", "Database"=>"SECO");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
//$conn = mssql_connect("localhost","ArisSeco","1234");
//mssql_select_db('SECO', $conn);

if( $conn )
{
    echo "Connection established.\n";
}
else
{
    echo "Connection could not be established.\n";
    die( print_r( sqlsrv_errors(), true));
}
//-----------------------------------------------
// Perform operations with connection.
//-----------------------------------------------

include_once('playStoreApi.php'); // including class file
$class_init = new PlayStoreApi; // initiating class

/* TOP PAID APPS MINING */

/*$page = 1;
do
{
    $topPaidApps = $class_init->topPaidApps($page); // calling topPaidApps

    //array_keys_multi($topPaidApps,&$vals);
    //print_r($topPaidApps);
    //array_keys_multi($vals,&$PaidNames);
    if ($topPaidApps!=0)
    {
        foreach ($topPaidApps as $k => $v)
        {
            $sql="INSERT INTO AppData
                (Application, AppDev)
                VALUES ('$v', 'Aris')";
            $query = "INSERT INTO TopPaidApps VALUES ('$v[app_title]' ,'$v[app_author]','$v[app_snippet]','$v[app_price]','$v[app_ratings]','$v[app_id]')";
            $stmt = sqlsrv_query( $conn, $query);
            if( $stmt === false ) 
            {
                //die( print_r( sqlsrv_errors(), true));
                print_r( sqlsrv_errors(), true);
            }
            //echo "Entered data successfully\n";
        }
    }
    $page = $page + 1;    
}while ($topPaidApps!=0);
*/

/* TOP FREE APPS MINING*/

/*$page = 1;
do
{
    $topFreeApps = $class_init->topFreeApps($page); // calling topFreeApps
    if ($topFreeApps!=0)
    {
        foreach ($topFreeApps as $k => $v)
        {
            $query = "INSERT INTO TopFreeApps VALUES ('$v[app_title]' ,'$v[app_author]','$v[app_snippet]','$v[app_ratings]','$v[app_id]')";
            $stmt = sqlsrv_query( $conn, $query);
            if( $stmt === false ) 
            {
                //die( print_r( sqlsrv_errors(), true));
                print_r( sqlsrv_errors(), true);
            }
            else
                echo "Entered data successfully\n";
        }
    }
    $page = $page + 1;    
}while ($topFreeApps!=0);*/

$item_id = 'com.touchtype.swiftkey';
$itemInfo = $class_init->itemInfo($item_id); // calling itemInfo
 
if($itemInfo !== 0)
{
 // print_r($itemInfo); // it will show all data inside an array
}
 
/* Close the connection. */
sqlsrv_close( $conn);

function array_keys_multi($array,&$vals)
{
    foreach ($array as $key => $value) {

        if (is_array($value)) {
            
            array_keys_multi($value,$vals);
            
        }else{
            
            $vals[] = $value;
        }
    }
    
    return $vals;
}
?>